package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.PmsProductCategoryMapper;
import com.mall.model.domain.PmsProductCategory;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【pms_product_category(产品分类)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class PmsProductCategoryApiImpl extends ServiceImpl<PmsProductCategoryMapper, PmsProductCategory>
        implements PmsProductCategoryApi {

    @Autowired
    private PmsProductCategoryMapper categoryMapper;

    @Override
    public PmsProductCategory findByName(String name) {
        LambdaQueryWrapper<PmsProductCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductCategory::getName,name);
        PmsProductCategory category = categoryMapper.selectOne(queryWrapper);
        return category;
    }

    @Override
    public void saveCategory(PmsProductCategory productCategory) {
        categoryMapper.insert(productCategory);
    }

    @Override
    public void deleteCategory(Long id) {
        categoryMapper.deleteById(id);
    }

    @Override
    public Page<PmsProductCategory> findParentId(Long parentId,Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<PmsProductCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductCategory::getParentId,parentId);
        Page<PmsProductCategory> page = new Page<>(pageNum,pageSize);
        Page<PmsProductCategory> list = categoryMapper.selectPage(page,queryWrapper);
        return list;
    }

    @Override
    public List<PmsProductCategory> findByIds(Long[] ids) {
        LambdaQueryWrapper<PmsProductCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(PmsProductCategory::getId,ids);
        List<PmsProductCategory> list = categoryMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public void updateCategory(PmsProductCategory category) {
        categoryMapper.updateById(category);
    }

    @Override
    public PmsProductCategory findById(Integer id) {
        PmsProductCategory category = categoryMapper.selectById(id);
        return category;
    }

    @Override
    public List<PmsProductCategory> findByParentId(long parentId) {
        LambdaQueryWrapper<PmsProductCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductCategory::getParentId,parentId);
        List<PmsProductCategory> list = categoryMapper.selectList(queryWrapper);
        return list;
    }


}




